<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Video;
use App\Models\SystemRegion;
use Dcat\Admin\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;
use Dcat\Admin\Support\Helper;

class VideoController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Video(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('video_title');
            $grid->column('first_img')->image('', 60, 60);
            $grid->column('is_top');
            $grid->column('weight');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->disableViewButton(); // 禁用详情按钮
            $grid->quickSearch(['article_title', 'content'])->placeholder('搜索...');
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Video(), function (Show $show) {
            $show->field('id');
            $show->field('video_title');
            $show->field('first_img');
            $show->field('video_url');
            $show->field('read_num');
            $show->field('zan_num');
            $show->field('collect_num');
            $show->field('like_num');
            $show->field('share_num');
            $show->field('category_id');
            $show->field('is_top');
            $show->field('weight');
            $show->field('user_id');
            $show->field('admin_id');
            $show->field('is_admin');
            $show->field('region_id');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Video(), function (Form $form) {
            $form->display('id');
            $form->text('video_title', '视频标题')->required();
            $form->image('first_img')->move('video/'.date('Y-m-d'))->autoUpload();
            $form->file('video_url')->move('video/'.date('Y-m-d'));
            $form->radio('is_top', '置顶')->options([1 => '是', 0 => '否'])->default(0);
            $form->number('weight')->placeholder('权重越高视频越靠前');

            $form->number('read_num');
            $form->number('zan_num');
            $form->number('collect_num');
            $form->number('like_num');
            $form->number('share_num');
            $form->hidden('admin_id')->value(Admin::user()->getKey());
            $form->hidden('is_admin')->value(1);
            $form->display('created_at');
            $form->display('updated_at');
            $form->disableViewCheck(true);
        });
    }
}
